using System;
using System.Diagnostics;
using RMA.Rhino;
using RMA.OpenNURBS;

namespace ResponsiveRhino
{
    ///<summary>
    /// A Rhino.NET plug-in can contain as many MRhinoCommand derived classes as it wants.
    /// DO NOT create an instance of this class (this is the responsibility of Rhino.NET.)
    /// A command wizard can be found in visual studio when adding a new item to the project.
    /// </summary>
    public class ResponsiveRhinoCommand : RMA.Rhino.MRhinoCommand
    {
        IRhinoCommandContext context;

        ///<summary>
        /// Rhino tracks commands by their unique ID. Every command must have a unique id.
        /// The Guid created by the project wizard is unique. You can create more Guids using
        /// the "Create Guid" tool in the Tools menu.
        ///</summary>
        ///<returns>The id for this command</returns>
        public override System.Guid CommandUUID()
        {
            return new System.Guid("{f4548c7d-79b5-47f5-9894-cc1946a0ee29}");
        }

        ///<returns>The command name as it appears on the Rhino command line</returns>
        public override string EnglishCommandName()
        {
            return "RhinoIO";
        }

        ///<summary> This gets called when when the user runs this command.</summary>
        public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
        {
            //TextWriterTraceListener tr = new TextWriterTraceListener(System.IO.File.CreateText("DebugLog\\" + System.DateTime.Now.ToString("yyMd_hhmm") + "_ResponsiveRhino.txt"));
            //Debug.Listeners.Add(tr);

            RhUtil.RhinoApp().Print(string.Format("This command starts a Windows form that communicates with a Wiimote and an Arduino board\n", EnglishCommandName()));
            this.context = context;

            Debug.WriteLine("Starting Rhino IO interface");
            Debug.Flush();

            Rhino_IO_UI ui = new Rhino_IO_UI(context);
            ui.ShowDialog();

            return IRhinoCommand.result.success;
        }
    }
}

